<template>
  <div class="online">
    <van-nav-bar
      title="已发布新闻"
      left-text=""
      left-arrow
      @click-left="onClickLeft"
      fixed
      placeholder
    />

    <div class="cart" v-for="(item, index) in dataList" :key="index">
      <van-card :desc="item.detail" :title="item.title" :thumb="item.pic">
        <template #footer>
          {{ new Date(item.time).toLocaleString() }}
          <van-button
            color="linear-gradient(to right, #ff6034, #ee0a24)"
            size="normal"
            @click="offSelf(item.id)"
            >撤销</van-button
          >
          <!-- <van-button size="mini"></van-button> -->
        </template>
      </van-card>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant"
import { Dialog } from "vant"
export default {
  data() {
    return {
      dataList: [],
    }
  },

  created() {
    // 获取数据
    this.getDataLidt()
  },
  methods: {
    onClickLeft() {
      this.$router.push("/myshop")
    },

    getDataLidt() {
      this.$api.news.getData().then((res) => {
        console.log(res)
        this.dataList = res.data
      })
    },

    offSelf(id) {
      Dialog.confirm({
        title: "提示",
        message: "是否撤销",
      })
        .then(() => {
          // on confirm
          let params = { id }
          this.$api.news.delData(params).then((res) => {
            console.log(res)
            if (res.code == 200) {
              Toast("撤销成功")
              this.getDataLidt()
            } else {
              Toast(res.msg)
            }
          })
        })
        .catch(() => {
          // on cancel
        })
    },
  },
}
</script>

<style lang="less" scoped></style>
